package com.itheima.demo09;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadPoolExecutor;

public class ThreadPool {
    public static void main(String[] args) {
        //创建没有线程上限的线程池
//        ExecutorService service = Executors.newCachedThreadPool();

        //创建有线程上限的线程池   最多同时执行3个线程，剩下的任务处于等待
        ExecutorService service = Executors.newFixedThreadPool(3); //参数线程数

        //向线程池提交任务
        service.submit(new MyThreadPool());
        service.submit(new MyThreadPool());
        service.submit(new MyThreadPool());
        service.submit(new MyThreadPool());
        service.submit(new MyThreadPool());


        //关闭线程
//        service.shutdown();


    }
}
